-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Adding description of how to test a command which expects user input #2398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
{ | ||
|
||
// .. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use 3 dots
} | ||
|
||
protected function getInputStream($input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asserting is not something that's usually done in a Command test. Mock objects are a better practise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this from the description on how to test commands. I think as a comment it is ok because it ilustrates that the command is now being executed and one can either test the outcome or end the test.
Impressive. I tried mocking DialogHelper using Mockery, with no luck, but this seems to be cleaner and easier. Unfortunately, this won't work if the order of questions for which we want user to provide answers to is non-deterministic. Is there any chance of getting a description about how to use Mockery in order to create more sophisticated tests for our commands? |
I see your problem. Actually, testing the command itself with Mockery doesn't make much sense, much in the same way testing a controller in a unit test doesn't make much sense. Both are more or less boilerplate code, connecting your services to some front end (http or cli). You could see if you can read the output stream and parse it, so you know which question is asked. Then you could provide some sort of mapping (if question x, answer with y). This of course means that rewriting one of your questions would break tests, but I guess it should be possible. Anyway, I think this should be either discussed on the mailing list or postet to SO as to not pollute the PR. |
Adding description of how to test a command which expects user input
Thanks Sebastian - awesome work! |
This PR adds a description on testing a command which uses the
DialogHelper
and expects some user input.One thing I'm not sure about is if I should add a link to the section about command testing. If so, where should I add it?